//
//  VSFindGiftCollectionViewCell.m
//  UI项目2.0
//
//  Created by dlios on 15/7/16.
//  Copyright (c) 2015年 星际科技. All rights reserved.
//

#import "VSFindGiftCollectionViewCell.h"
#import "VSFrameGrand.h"
#import "UIImageView+WebCache.h"


@interface VSFindGiftCollectionViewCell ()

@property(nonatomic,assign)CGFloat height;

@end

@implementation VSFindGiftCollectionViewCell

- (void)dealloc
{
    [_MainImageView release];
    [_MainLabel release];
    [_findModel release];
    [_BackGroundView release];
    [_BackGroundLabelView release];
    [_GiftLikeImageView release];
    [_GiftLikeLabel release];
    [_GiftWireLabel release];
    [_GiftIconLabel release];
    [super dealloc];
}

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
       
        self.BackGroundView = [[[UIImageView alloc]init]autorelease];
        [self.contentView addSubview:self.BackGroundView];
        self.BackGroundView.userInteractionEnabled = YES;
        
        self.MainImageView = [[[UIImageView alloc]init] autorelease];
        [self.BackGroundView addSubview:self.MainImageView];
       
        
        self.BackGroundLabelView = [[[UIView alloc]init]autorelease];
        [self.BackGroundView addSubview:self.BackGroundLabelView];
        self.BackGroundLabelView.backgroundColor = [UIColor whiteColor];
        
        self.MainLabel = [[[UILabel alloc]init] autorelease];
        self.MainLabel.numberOfLines = 0;
        [self.BackGroundLabelView addSubview:self.MainLabel];
        
        self.GiftLikeImageView = [[[UIImageView alloc]init]autorelease];
        [self.BackGroundLabelView addSubview:self.GiftLikeImageView];
        
        self.GiftLikeLabel = [[[UILabel alloc]init]autorelease];
        [self.BackGroundLabelView addSubview:self.GiftLikeLabel];
        self.GiftLikeLabel.numberOfLines = 1;
        
        self.GiftWireLabel = [[[UILabel alloc]init]autorelease];
        [self.BackGroundLabelView addSubview:self.GiftWireLabel];
        self.GiftWireLabel.backgroundColor = [UIColor lightGrayColor];
        self.GiftWireLabel.alpha = 0.7;
        
        self.GiftIconLabel = [[[UIImageView alloc]init]autorelease];
        [self.BackGroundLabelView addSubview:self.GiftIconLabel];
    }
    return self;
}

- (void)applyLayoutAttributes:(UICollectionViewLayoutAttributes *)layoutAttributes
{
    
    _height = layoutAttributes.frame.size.height;
    self.BackGroundView.frame = layoutAttributes.bounds;
    
}

- (CGRect)heightWithText:(NSString *)text
{
    NSDictionary *dic = @{NSFontAttributeName:[UIFont systemFontOfSize:15]};
    CGSize size = CGSizeMake((SCREEN_WIDTH - 30) / 2 - 8, 60);
    CGRect rect = [text boundingRectWithSize:size options:NSStringDrawingUsesLineFragmentOrigin attributes:dic context:nil];
    return rect;
}

- (void)setFindModel:(VSFindGiftModel *)findModel
{
    if (_findModel != findModel) {
        [_findModel release];
        _findModel = [findModel retain];
    }
    
    CGFloat everyWidth = (SCREEN_WIDTH - 30) / 2;
    self.BackGroundView.image = [UIImage imageNamed:@"background002.png"];
    CGRect labelRect = [self heightWithText:findModel.msg];
    self.MainImageView.frame = CGRectMake(0, 0, everyWidth, _height - labelRect.size.height - 39);
    self.BackGroundLabelView.frame = CGRectMake(0, self.MainImageView.frame.size.height, self.MainImageView.frame.size.width, _height - self.MainImageView.frame.size.height);
    self.MainLabel.frame = CGRectMake(self.MainImageView.frame.origin.x + 8, 5, labelRect.size.width , labelRect.size.height);
    self.GiftWireLabel.frame = CGRectMake(30, self.MainLabel.frame.size.height + 10, everyWidth - 30, 1);
    self.GiftLikeImageView.frame = CGRectMake(10, self.MainLabel.frame.size.height + 16, 16, 16);
    self.GiftLikeLabel.frame = CGRectMake(self.GiftLikeImageView.frame.origin.x + self.GiftLikeImageView.frame.size.width + 8, self.GiftLikeImageView.frame.origin.y, 100, self.GiftLikeImageView.frame.size.height);
    self.GiftIconLabel.frame = CGRectMake(everyWidth - 18 - 10, self.GiftLikeImageView.frame.origin.y, 18, 18);
    
    
    [self.MainImageView setImageWithURL:[NSURL URLWithString:[findModel.photo objectForKey:@"path"]]];
    self.MainLabel.text = findModel.msg;
    self.MainLabel.font = [UIFont systemFontOfSize:13];
    [self.GiftIconLabel setImageWithURL:[NSURL URLWithString:findModel.icon_url]];
    self.GiftLikeLabel.text = [NSString stringWithFormat:@"%@", findModel.favorite_count];
    self.GiftLikeLabel.font = [UIFont systemFontOfSize:15];
    self.GiftLikeImageView.image = [UIImage imageNamed:@"iconfont-xin001.png"];
}


@end
